# _*_coding:utf-8 _*_
# @Time　　:2021/6/20 22:51
# @Author : mojin
# @Email : 397135766@qq.com
# @File　　  :conftest.py
# @Software  :PyCharm

from common.base_driver import BaseDriver
import pytest
import random


driver = None


def pytest_addoption(parser):
    parser.addoption("--cmdopt", action="store", default="device_info", help=None)


@pytest.fixture(scope='session')
def cmdopt(pytestconfig):
    # 两种写法
    return pytestconfig.getoption("--cmdopt")
    # return pytestconfig.option.cmdopt


# 定义公共的fixture
@pytest.fixture(scope='session')
def driver_and_device(cmdopt):
    device_info=eval(cmdopt)
    global driver
    base_driver = BaseDriver(device_info[0])
    driver = base_driver.base_driver()

    yield [driver,device_info]
    driver.close_app()
    driver.quit()


# @pytest.fixture
# def device(cmdopt):
#     yield eval(cmdopt)


def pytest_itemcollected(item):
    item._nodeid = str(random.randint(1, 1000)) + '_' + item . _nodeid
